<template>
  <div class="left-sideBar">
    <div class="sideBar-title">全部标签</div>
    <div class="tag-container">
      <div class="ev-tags-container" v-for="tag in tagSet" :key="tag" @click="clickTag(tag)" :class="selectedSet.indexOf(tag)===-1?'':'ev-tags-selected'" >
        <i class="iconfont">&#xe604;</i>
        <span class="ev-tags"  v-html="tag" ></span>
      </div>
    </div>
  </div>
</template>

<script>
import { getTagsByTheme} from "@/api/Tag";

export default {
  name: "TagSideBar",
  props:['ThemeName'],
  data() {
    return {
      tagSet: [],
      selectedSet: []
    }
  },
  created() {
    this.getAllTags(this.ThemeName)
  },
  methods:{
    getAllTags(themeName) {
      getTagsByTheme({themeName}).then((res) => {
        this.tagSet = res.data.data
      })
    },
  clickTag(tags) {
      let pos=this.selectedSet.indexOf(tags)
      if(pos!==-1){
        this.selectedSet.splice(pos,1)
      }
      else
      this.selectedSet.push(tags)
      this.$emit('selectTag',this.selectedSet)
  }
  },
  watch:{
    ThemeName(){
      this.selectedSet=[]
      this.getAllTags(this.ThemeName)
    }
  }
}
</script>

<style scoped>
.left-sideBar {
  width: 30%;
  height: 100%;
  margin-left: 40px;
  position: sticky;
  top: 20px;
}
.sideBar-title {
  text-align: left;
  font-size: 30px;
  font-weight: bold;
}

.tag-container {
  display: flex;
  width: 100%;
  flex-wrap: wrap;
  padding: 10px 10px;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}
.ev-tags {

  text-align: center;
  white-space: nowrap;
  margin: 5px 5px;
  padding: 4px 4px;
  cursor: pointer;
}
.ev-tags-container{
  border: 1px solid #eeeeee;
  margin-right: 17px;
  cursor: pointer;
  margin-bottom: 15px;
  font-size: 20px;
}
.ev-tags-container:hover {
  color: cornflowerblue;
  border: 1px solid #3a8fb7;
}
.ev-tags-selected {
  background-color:lightskyblue;
  font-weight: bold;
}
</style>
